package com.hhu.userservice.utils;

import org.springframework.util.Base64Utils;

import java.security.MessageDigest;

/**
 * create by: yaodao
 * description: 一个简单的Md5工具
 */
public class Md5Util {
    public static String md5Encode(String val) {
        try {
            String salt = "hhu-project";
            //获取一个Md5实例
            MessageDigest digest = MessageDigest.getInstance("MD5");
            //使用这个MD5生成值
            byte[] buf = digest.digest((val + salt).getBytes());
            return new String(Base64Utils.encode(buf));
        } catch (Exception e) {
            return val;
        }
    }
}
